home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / VideoToolbox 97.08.16 / (Utilities) / TestAttenuator / TestAttenuator.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-02  |  5.0 KB  |  203 lines  |  [TEXT/CWIE]

  1. /*
  2. TestAttenuator.c
  3. This produced a simple test pattern that allows a quick yes/no evaluation of the
  4. attenuator before shipping. Mainly this is a check to make sure that all the
  5. resistors were soldered correctly.
  6. HISTORY:
  7. 11/89     dgp wrote it
  8. 9/9/90    dgp    make the arrays static.
  9. 10/17/90    dgp    remove unused variable
  10. 2/16/91        dgp    added check for fpu and color quickdraw
  11. 8/24/91    dgp    Made compatible with THINK C 5.0.
  12. 4/27/92    dgp    call SetDepth to set screen to 8 bits.
  13. 8/27/92    dgp    replace SysEnvirons() by Gestalt()
  14. 2/7/93    dgp    updated to use SetPixelsQuickly.
  15. 7/1/97    dgp    After GDOpenWindow, now call ShowWindow, since GDOpenWindow no longer does.
  16. */
  17. #include "VideoToolbox.h"
  18. #include "Luminance.h"
  19.  
  20. #define XMAX         640        /* Maximum horizontal coordinate */ 
  21. #define YMAX         480        /* Maxumum vertical coordinate */
  22.  
  23. void TestAttenuator(void);
  24.  
  25. void main(void)
  26. {
  27.     Require(gestalt8BitQD);
  28.     TestAttenuator();
  29. }
  30.  
  31. void TestAttenuator(void)
  32. {
  33.     register short i,j,k;
  34.     double a,A,AA;
  35.     CWindowPtr window=NULL;
  36.     WindowPtr oldWindow=NULL;
  37.     GDHandle device=NULL,oldGDHandle=NULL;
  38.     static LuminanceRecord LR;
  39.     short n,mode;
  40.     static double fy[YMAX];
  41.     double c;
  42.     static unsigned long row[XMAX];
  43.     short oldScreen;
  44.     char string[100];
  45.     
  46.     /* parameters of the screen calibration */
  47.     
  48.     MaximizeConsoleHeight();
  49.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  50.         console_options.top=YMAX/2-40;
  51.         console_options.nrows=7;
  52.         console_options.txSize=9;
  53.     #elif __MWERKS__
  54.         SIOUXSettings.toppixel=YMAX/2-40;
  55.         SIOUXSettings.rows=7;
  56.         SIOUXSettings.columns=60;
  57.         SIOUXSettings.autocloseonquit=0;
  58.     #endif
  59.     printf("Welcome to TestAttenuator.\n");
  60.     #include "LuminanceRecord1.h"                    // read at compile time
  61.     printf("%s\n",LR.notes);
  62.     oldScreen=LR.screen;
  63.     i=LR.screen;
  64.     do{
  65.         if(GetScreenDevice(1)!=NULL)i=ChooseScreen(i,"Which screen?");
  66.         else i=0;
  67.         device=GetScreenDevice(i);
  68.     }while(device==NULL);
  69.     LR.screen=i;
  70.     sprintf(string,"LuminanceRecord%d.h",LR.screen);
  71.     i=ReadLuminanceRecord(string,&LR,0);        // try to read latest LuminanceRecord
  72.     if(i<1)printf("Warning: couldn't find “%s”. Calibrating screen %d.\n"
  73.         ,string,LR.screen);
  74.     else oldScreen=LR.screen;
  75.  
  76.     /* Find device corresponding to the experimental screen. */
  77.     oldGDHandle = GetGDevice();
  78.     device = GetScreenDevice(LR.screen);
  79.     if(GDClutSize(device)!=256 && NewPaletteManager()){
  80.         mode=HasDepth(device,8,1,1);
  81.         if(mode!=0)SetDepth(device,mode,1,1);        // 8-bit pixelSize, color
  82.     }
  83.     if(GDClutSize(device)!=256){
  84.         PrintfExit("Sorry, I require a screen with 256 colors.\n");
  85.     }
  86.     
  87.     GetPort(&oldWindow);
  88.     window = GDOpenWindow(device);
  89.     ShowWindow((WindowPtr)window);
  90.     SetPort((WindowPtr)window);
  91.     
  92.     for(j=0;j<YMAX/2;j++){
  93.         fy[j]=cos(j*2.0*PI/80.0);
  94.     }
  95.     c=1.0;
  96.     SetLuminances(device,&LR,11,90,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  97.     c/=6.0;
  98.     SetLuminances(device,&LR,91,170,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  99.     c/=6.0;
  100.     SetLuminances(device,&LR,171,250,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  101.     /* Display a swept-contrast sinusoid */
  102.     for(j=0;j<YMAX/2;j++){
  103.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  104.         k+=11;
  105.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  106.         SetPixelsQuickly(0,j,row,1+XMAX/3);
  107.     }
  108.     c *=6.0;
  109.     for(j=0;j<YMAX/2;j++){
  110.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  111.         k+=91;
  112.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  113.         SetPixelsQuickly(XMAX/3,j,row,1+XMAX/3);
  114.     }
  115.     c *=6.0;
  116.     for(j=0;j<YMAX/2;j++){
  117.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  118.         k+=171;
  119.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  120.         SetPixelsQuickly(2*XMAX/3,j,row,1+XMAX/3);
  121.     }
  122.  
  123.     /* compute three clut entries that ought to produce equal luminances */
  124.     AA=LToV(&LR,LR.LMax/4.0);
  125.     printf("%f cd/m^2 equivalent number is %f\n",VToL(&LR,AA),AA);
  126.     i=251;
  127.     A=AA;
  128.     a=A/LR.r;
  129.     if(a>255.) n=255;
  130.     else n=a;
  131.     LR.table[i].rgb.red=n<<8;
  132.     A -= n*LR.r;
  133.     a=A/LR.g;
  134.     if(a>255.) n=255;
  135.     else n=a;
  136.     LR.table[i].rgb.green=n<<8;
  137.     A -= n*LR.g;
  138.     a=A/LR.b;
  139.     if(a>255.) n=255;
  140.     else n=a;
  141.     LR.table[i].rgb.blue=n<<8;
  142.     A -= n*LR.b;
  143.     i++;
  144.     A=AA;
  145.     a=A/LR.g;
  146.     if(a>255.) n=255;
  147.     else n=a;
  148.     LR.table[i].rgb.green=n<<8;
  149.     A -= n*LR.g;
  150.     a=A/LR.b;
  151.     if(a>255.) n=255;
  152.     else n=a;
  153.     LR.table[i].rgb.blue=n<<8;
  154.     A -= n*LR.b;
  155.     a=A/LR.r;
  156.     if(a>255.) n=255;
  157.     else n=a;
  158.     LR.table[i].rgb.red=n<<8;
  159.     A -= n*LR.r;
  160.     i++;
  161.     A=AA;
  162.     a=A/LR.b;
  163.     if(a>255.) n=255;
  164.     else n=a;
  165.     LR.table[i].rgb.blue=n<<8;
  166.     A -= n*LR.b;
  167.     a=A/LR.r;
  168.     if(a>255.) n=255;
  169.     else n=a;
  170.     LR.table[i].rgb.red=n<<8;
  171.     A -= n*LR.r;
  172.     a=A/LR.g;
  173.     if(a>255.) n=255;
  174.     else n=a;
  175.     LR.table[i].rgb.green=n<<8;
  176.     A -= n*LR.g;
  177.     i++;
  178.     for(i=251;i<254;i++) printf("%4d,%4d,%4d = %6.2f == %7.3f cd/m^2\n",
  179.         LR.table[i].rgb.red/256,LR.table[i].rgb.green/256,LR.table[i].rgb.blue/256,
  180.         LToV(&LR,GetLuminance(NULL,&LR,i)), GetLuminance(NULL,&LR,i));
  181.     LoadLuminances(device,&LR,251,253);
  182.     
  183.     /* Display stripes */
  184.     for(i=0;i<XMAX;) {
  185.         for(k=0;k<10;k++)row[i++]=251;
  186.         for(k=0;k<10;k++)row[i++]=252;
  187.         for(k=0;k<10;k++)row[i++]=253;
  188.     }
  189.     for(j=YMAX/2;j<YMAX;j++)SetPixelsQuickly(0,j,row,XMAX);
  190.     
  191.     printf("Hit return to quit.");
  192.     getchar();
  193.     SetPort(oldWindow);
  194.     SetGDevice(oldGDHandle);
  195.     GDDisposeWindow(window);
  196.     RestoreCluts();
  197.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  198.         abort();
  199.     #elif __MWERKS__
  200.         SIOUXSettings.autocloseonquit=1;
  201.     #endif
  202. }
  203.